#pragma once

#include <string>
#include <jsoncpp/json/json.h>

namespace WordMemory
{
    struct Vocabulary
    {
        int id;
        int user_id;
        std::string name;
        int word_count;
        bool is_default;
        bool is_favorites;
        bool is_mistakes_book;

        Vocabulary(int id = 0,
                   int user_id = 0,
                   const std::string& name = "",
                   int word_count = 0,
                   bool is_default = false,
                   bool is_favorites = false,
                   bool is_mistakes_book_val = false)
            : id(id)
            , user_id(user_id)
            , name(name)
            , word_count(word_count)
            , is_default(is_default)
            , is_favorites(is_favorites)
            , is_mistakes_book(is_mistakes_book_val)
        {}

        Json::Value to_json() const
        {
            Json::Value json;
            json["id"] = id;
            json["user_id"] = user_id;
            json["name"] = name;
            json["word_count"] = word_count;
            json["is_default"] = is_default;
            json["is_favorites"] = is_favorites;
            json["is_mistakes_book"] = is_mistakes_book;
            return json;
        }

        void from_json(const Json::Value& json)
        {
            id = json["id"].asInt();
            user_id = json["user_id"].asInt();
            name = json["name"].asString();
            word_count = json["word_count"].asInt();
            is_default = json["is_default"].asBool();
            is_favorites = json["is_favorites"].asBool();
            is_mistakes_book = json.get("is_mistakes_book", false).asBool();
        }
    };
}